% Test polynomial multiplications
% In this case polynomials are decimal number representations for
% easy testing
%--------------------------------------------------------------------------------
base = 10;

% N sets of random integer operands in range [low, high]
N=100;
low=1;
high=2^10;   % let's not exceed 32-bit integer range here
high = 10000;

x_set = floor(low + (high-low).*rand(N,1));
y_set = floor(low + (high-low).*rand(N,1));

error_count=0;
error_sum=0;

for k=1:N
  x = x_set(k);
  y = y_set(k);
  z = x*y   % reference
  
  xv = int2vect(x);
  yv = int2vect(y);  
  zv = fft_poly_mult(xv, yv);

  zv_int = vect2int(zv,base);
  
  error = z-zv_int;
  if error>0
    error_sum=error_sum+error;    
    error_count=error_count+1;
  end
end

error_count
disp('avg error:')
error_sum/error_count

